//
//  StrategyArticleViewController.m
//  wedding
//
//  Created by 常宽 on 15/1/26.
//  Copyright (c) 2015年 常宽. All rights reserved.
//

#import "StrategyArticleViewController.h"
#import "StrategySecModel.h"    // 传进来的model
#import "ArticleModel.h"        // 本类的model

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface StrategyArticleViewController ()

/// 数据数组
@property (nonatomic, retain)NSMutableArray *dataArray;
/// webView
@property (nonatomic, retain)UIWebView *webView;
@end

@implementation StrategyArticleViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.dataArray = [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)netWorking
{
    NSString *string = [NSString stringWithFormat:@"http://data.halobear.cn/mapi/index.php?act=article&id=%@", self.secModel.article_id];
    [NetHandler networkWithURL:string completion:^(id result) {
        NSDictionary *dic1 = [result objectForKey:@"article"];
        ArticleModel *model = [[ArticleModel alloc] init];
        [model setValuesForKeysWithDictionary:dic1];
        [self.dataArray addObject:model];
        
        NSString *urlStr = model.content;
//        NSLog(@"%@", urlStr);
        [self.webView loadHTMLString:urlStr baseURL:nil];
        self.title = model.title;
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 二级页面隐藏tabBar
    self.tabBarController.tabBar.hidden = YES;
    // 重写返回上级页面方法
    UIImage *backImage = [[UIImage imageNamed:@"返回.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem= [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(popBack:)];
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH,  HEIGHT - 5)];
    self.webView.backgroundColor = [WebColor crimson];
    [self.view addSubview:self.webView];
    [self netWorking];
}
// 返回上级页面
- (void)popBack:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
